<template>
	<view class="wocomplete">
		<view class="ag-topbg"></view>
		<view class="wocomplete-card">
			<view class="wocomplete-card__head">
				<view class="ag-womarker">{{firstChar(orderDetailData.WoType)}}</view>
				<view class="wocomplete-card__col">
					<view class="wocomplete-card__col-row">
						<text class="wocomplete-card__name">{{orderDetailData.WoType}}</text>
						<view class="wocomplete-card__no">{{orderDetailData.WoNum}}</view>
					</view>
					<view class="wocomplete-card__col-time" v-if="false">
						<text>总部派工：{{orderDetailData.AssignDate}}</text>
						<text>网点派工：{{orderDetailData.ServiceSiteAcceptDate}}</text>
					</view>
				</view>
			</view>

			<!-- 维修工单完工 -->
			<view class="wocomplete-card__body">
				<textarea class="wocomplete-card__remark" placeholder="完工备注" :value="OrderRremark" @input="changeOrderRremark"></textarea>
				<view class="wocomplete-fix-row">
					<view style="color: #DD524D;margin-top: 15rpx;">*</view>
					<text>维修方式：</text>
					<picker mode="selector" :range="repairTypeList" :value="repairTypeIndex" range-key="text" @change="changeRrpairType">
						<AGInput customStyle="margin-top:0px;" readonly dropdown placeholder="维修方式" :value="repairTypeList[repairTypeIndex].text" />
					</picker>
				</view>
				<AGInput icon="calender" readonly placeholder="客户要求保养日期" @openCalender="onOpenCalender(index,$event)" :value="CustomerRequiresMaintenanceDate" />
				<uni-calendar ref="cusReqDatePicker" :date="CustomerRequiresMaintenanceDate" :insert="false" :lunar="true"
				 :start-date="'2019-3-2'" @confirm="cusReqDateConfirm" />
				<!-- <yu-datetime-picker ref="cusReqDatePicker" :startYear="startYear" :value="CustomerRequiresMaintenanceDate" :isAll="true"
				 :current="false" @confirm="cusReqDateConfirm" /> -->
				<view class="wocomplete-card__content1" v-for="(productItem , index) in orderDetailData.WoProuduct" :key="productItem.WoObjectId">
					<!-- 一行两个 -->
					<!-- <view class="ag-cellgroup"> -->

					<view class="ag-cell">
						<view class="ag-cell__label">
							<text>产品编码：</text>
						</view>
						<view class="ag-cell__value">
							<text>{{productItem.ProductNum}}</text>
						</view>
					</view>

					<view class="ag-cell">
						<view class="ag-cell__label">
							<text>产品类型：</text>
						</view>
						<view class="ag-cell__value">
							<text>{{productItem.ProdTypeGroup||""}}</text>
						</view>
					</view>
					<!-- </view> -->
					<!-- 一行一个 -->
					<view class="ag-cell">
						<view class="ag-cell__label">
							<text>产品名称：</text>
						</view>
						<view class="ag-cell__value">
							<text>{{productItem.ProductName}}</text>
						</view>
					</view>
					<view class="ag-cell">
						<view class="ag-cell__label">
							<text>保修开始时间：</text>
						</view>
						<view class="ag-cell__value">
							<text>{{productItem.WarrantyStartDate}}</text>
						</view>
					</view>
					<view class="ag-cell">
						<view class="ag-cell__label">
							<text>保修结束时间：</text>
						</view>
						<view class="ag-cell__value">
							<text>{{productItem.WarrantyEndDate}}</text>
						</view>
					</view>
					<view class="ag-cell">
						<view class="ag-cell__label">
							<text>套装产品：</text>
						</view>
						<view class="ag-cell__value">
							<text>{{productItem.SuitProductName||""}}</text>
						</view>
					</view>
					<view class="ag-cell">
						<view class="ag-cell__label">
							<text>客户分类：</text>
						</view>
						<view class="ag-cell__value">
							<text>{{orderDetailData.AccountClassify}}</text>
						</view>
					</view>
					<view class="ag-cell">
						<view class="ag-cell__label">
							<text>只换不修结束时间：</text>
						</view>
						<view class="ag-cell__value">
							<text>{{productItem.OnlyChangeEndDate||""}}</text>
						</view>
					</view>
					<view class="ag-cell">
						<view class="ag-cell__label">
							<text>安装位置：</text>
						</view>
						<view class="ag-cell__value">
							<text>{{productItem.InstallLocation||""}}</text>
						</view>
					</view>
					<view class="ag-cell">
						<view class="ag-cell__label">
							<text>购机来源：</text>
						</view>
						<view class="ag-cell__value">
							<text>{{productItem.PurchaseSourceText||""}}</text>
						</view>
					</view>
					<view class="ag-cell">
						<view class="ag-cell__label">
							<text>购机卖场名称：</text>
						</view>
						<view class="ag-cell__value">
							<text>{{productItem.PurchaseChanel||""}}</text>
						</view>
					</view>
					<view class="ag-cell">
						<view class="ag-cell__label">
							<text>物流码：</text>
						</view>
						<view class="ag-cell__value">
							<text>{{productItem.Barcode||""}}</text>
						</view>
					</view>
					<view class="ag-cell">
						<view class="ag-cell__label">
							<text>物流码有效性：</text>
						</view>
						<view class="ag-cell__value">
							<text>{{productItem.IsSerialValid||""}}</text>
						</view>
					</view>
					<view class="ag-cell" v-if="productItem.ProductImage">
						<view class="ag-cell__value">
							<image mode="aspectFill" class="img-prod" :src="productItem.ProductImage" />
						</view>
					</view>
					<AGInput icon="qrcode" placeholder="物流码" @openQrcode="onOpenQrcode(index,$event)" @onBlur="onBlurLogisticsCode(index,$event)"
					 :value="productItem.Barcode" :disabled="productItem.IsProductConfirmed" />
					<AGInput icon="search" placeholder="产品" @openSearch="onOpenProdSearch(index,$event)" :value="productItem.ProductNum"
					 :disabled="productItem.IsProductConfirmed" />
					<AGInput icon="calender" placeholder="保修开始时间" @openCalender="onOpenCalender(index,$event)" :value="productItem.PurchaseDate | GetDate"
					 :disabled="productItem.IsProductConfirmed" />
					<button class="cu-btn lg primary block" @click.stop="onAffirmProduct(index)">确认产品</button>
					<uni-calendar ref="purchaseDatePicker" :date="productItem.PurchaseDate||''" :insert="false" :lunar="false"
					 @confirm="purchaseConfirm(index,$event)" />
					<!-- 维修列表 维修工单中使用 -->
					<view class="repair">
						<view class="repair-head">
							<text class="repair-head__title">维修信息</text>
							<image class="repair-head__add" src="../../../static/img/icon-add.png" @click.stop="onClickToAddrepair(index,$event)" />
						</view>
						<view class="repair-list">
							<view v-for="(addrepairItem, repairIndex) in orderDetailData.WoProuduct[index].Repairs" :key="repairIndex" class="repair-item">
								<view class="repair-item__head">
									<text class="repair-item__head-title">故障信息-{{repairIndex+1}}：</text>
									<image class="repair-item__head-edit" src="../../../static/img/icon-edit.png" style=" margin: 5px; width: 15px;height: 15px;"
									 @click.stop="EditCurrentRepairData(repairIndex,index)" />
									<image class="repair-item__head-del" src="../../../static/img/icon-close.png" style=" margin: 5px; width: 15px;height: 15px;"
									 @click.stop="DelRepairData(repairIndex)" />
								</view>
								<view class="repair-item__body">
									<view class="ag-cell">
										<view class="ag-cell__label">
											<text>故障信息：</text>
										</view>
										<view class="ag-cell__value">
											<!-- <text>故障类别 - 故障现象 - 故障部位 - 故障原因 - 解决方法</text> -->
											<text>{{selectFaultItemPath(addrepairItem.confirmSelectFaultItem)}}</text>
										</view>
									</view>
									<!-- <view class="ag-cell">
										<view class="ag-cell__label">
											<text>故障信息：</text>
										</view>
										<view class="ag-cell__value">
											<text>电气故障 - 加热故障 - 自动复位温控器 - 自动复位温控器
												异常（闭合或断开） - 更换自动复位温控器</text>
										</view>
									</view> -->
									<view class="ag-cell" v-if="addrepairItem.faultPartItem.PartsNum">
										<view class="ag-cell__label">
											<text>故障件：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{addrepairItem.faultPartItem.PartsNum}}</text>
											<view class="ag-status-tag primary" style="width: 80rpx;margin-left: 5rpx">
												<text>保修件: {{addrepairItem.faultPartItem.IsWarranty?'是' : '否'}}</text>
											</view>
											<view class="ag-status-tag primary" style="width: 90rpx;margin-left: 5rpx">
												<text>保内保外: {{addrepairItem.faultPartItem.InOrOffWarranty | displayOrOffWarranty}}</text>
											</view>
										</view>
									</view>
									<view class="ag-cell" v-if="addrepairItem.faultPartItem.PartsName">
										<view class="ag-cell__label">
											<text>故障件名称：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{addrepairItem.faultPartItem.PartsName}}</text>
										</view>
									</view>
									<view class="ag-cell" v-if="addrepairItem.switchReplacePart">
										<view class="ag-cell__label">
											<text>换件：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{addrepairItem.switchReplacePart?'是' : '否'}}</text>
										</view>
									</view>
									<view class="ag-cell" v-if="addrepairItem.switchReplacePart">
										<view class="ag-cell__label">
											<text>更换件：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{addrepairItem.changeFaultPartItem.PartsNum}}</text>
											<view class="ag-status-tag primary" style="width: 60rpx;margin-left: 5rpx">
												<text>￥ {{addrepairItem.changeFaultPartItem.Price}}</text>
											</view>
											<view class="ag-status-tag primary"  style="width: 120rpx;margin-left: 5rpx;">
												<text>网点库存: {{addrepairItem.changeFaultPartItem.SiteStock}}</text>
											</view>
										</view>
									</view>
									<view class="ag-cell" v-if="addrepairItem.RepairMarks">
										<view class="ag-cell__label">
											<text>维修备注：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{addrepairItem.RepairMarks}}</text>
										</view>
									</view>
									<view class="ag-cell" v-if="addrepairItem.WarrantyMarks">
										<view class="ag-cell__label">
											<text>备注：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{addrepairItem.WarrantyMarks}}</text>
										</view>
									</view>
								</view>
							</view>
						</view>
						<view class="repair-footer">
							<view class="repair-footer__head">
								<text>更换配件数量: {{orderDetailData.WoProuduct[index].addrepairDataTotal||'0'}}</text>
								<text>保外配件费用: {{orderDetailData.WoProuduct[index].PriceTotal||'0'}} 元</text>
							</view>
							<!-- <AGInput placeholder="实际收款总金额（保内工单不显示）" @change="ChangeRemark"/> -->
						</view>
					</view>
					<!-- 维修列表 维修工单中使用 -->

					<!-- 水质检测 -->
					<view class="repair" v-if="productItem.IsRequired">
						<view class="repair-head">
							<text class="repair-head__title">水质检测信息</text>
							<image v-if="productItem.isShowWaterAnalysisAddBtn" class="repair-head__add" src="../../../static/img/icon-add.png"
							 @click="onOpenWaterQualityPopup(index,$event)" />
						</view>
						<view class="repair-list" v-if="!productItem.isShowWaterAnalysisAddBtn">
							<view class="repair-item">
								<view class="repair-item__head">
									<text class="repair-item__head-title">水质检测结果</text>
									<image v-if="!productItem.isShowWaterAnalysisAddBtn" class="repair-item__head-edit" style=" margin: 5px; width: 17px;height: 17px;"
									 src="../../../static/img/icon-edit.png" @click="onOpenWaterQualityPopup(index,$event)" />
									<image v-if="!productItem.isShowWaterAnalysisAddBtn" style=" margin: 5px; width: 17px;height: 17px;" class="repair-item__head-del"
									 src="../../../static/img/icon-close.png" @click="onCanleWaterQuality(index)" />
								</view>
								<view class="repair-item__body">
									<view class="ag-cell">
										<view class="ag-cell__label">
											<text>原水TDS：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{productItem.OriTDS}}</text>
										</view>
									</view>
									<view class="ag-cell">
										<view class="ag-cell__label">
											<text>原水水温：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{productItem.OriTemperature}}</text>
										</view>
									</view>
									<view class="ag-cell">
										<view class="ag-cell__label">
											<text>原水硬度：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{productItem.OriHardness}}</text>
										</view>
									</view>
									<view class="ag-cell">
										<view class="ag-cell__label">
											<text>原水余氯：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{productItem.OriChlorine}}</text>
										</view>
									</view>
									<view class="ag-cell">
										<view class="ag-cell__label">
											<text>纯水TDS：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{productItem.NewTDS}}</text>
										</view>
									</view>
									<view class="ag-cell">
										<view class="ag-cell__label">
											<text>软化后硬度：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{productItem.NewHardness}}</text>
										</view>
									</view>
									<view class="ag-cell">
										<view class="ag-cell__label">
											<text>净化余氯：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{productItem.NewChlorine}}</text>
										</view>
									</view>
									<view class="ag-cell">
										<view class="ag-cell__label">
											<text>检测确认：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{productItem.IsWaterAnalysis?"是":"否"}}</text>
										</view>
									</view>
									<view class="ag-cell">
										<view class="ag-cell__label">
											<text>是否必须水质检测：</text>
										</view>
										<view class="ag-cell__value">
											<text>{{productItem.IsRequired?"是":"否"}}</text>
										</view>
									</view>
								</view>
							</view>
						</view>
						<view class="repair-footer">
						</view>
						<waterQuality ref="waterQuality" :proItem="productItem" :fieldReq="ParseWaterAnalysisFieldRequired(productItem.WaterAnalysisFieldRequired)"
						 @onSaveWaterQuality="saveWaterQuality(index,$event)" />
					</view>
					<!-- 水质检测 -->
				</view>
			</view>
			<view class="wocomplete-fix-row" v-if="isShowActualReceiptAmountField">
				<text style="margin-left: 60rpx;">实际收款总金额：</text>
				<AGInput placeholder="实际收款总金额（保内工单不显示）" :value="ActualReceiptAmount" @change="ChangeActualReceiptAmount" width="30rpx" />
			</view>
			<!-- <AGInput placeholder="实际收款总金额（保内工单不显示）" v-if="isShowActualReceiptAmountField" :value="ActualReceiptAmount" @change="ChangeActualReceiptAmount" /> -->
		</view>

		<view class="wocomplete-section">
			<view class="wocomplete-section__head">
				<view>现场图片</view>
				<navigator url="../../woupload/index" v-if="orderDetailData.WoItemPicture"><text class="cuIcon-upload">上传图片</text></navigator>
			</view>
			<scroll-view :scroll-x="true" class="wocomplete-listimage">
				<view class="wocomplete-listimage__inner">
					<image class="wocomplete-listimage__item" v-for="(picItem, picIndex) in orderDetailData.WoItemPicture" :key="picIndex"
					 :src="getImageBase64(picItem)" @tap="navToUploadImg" />
					<navigator url="../../woupload/index" v-if="!orderDetailData.WoItemPicture"><text class="cuIcon-upload">上传图片</text></navigator>
				</view>
			</scroll-view>
		</view>

		<view class="wocomplete-section">
			<view class="wocomplete-section__head">
				<view>完工处理状态</view>
			</view>
			<view class="wocomplete-listprocess">
				<view class="wocomplete-listprocess__item">
					<text class="wocomplete-listprocess__title">数据同步：{{orderDetailData.DataSyncStateName}}</text>
					<text class="wocomplete-listprocess__desc">{{orderDetailData.DataSyncInfo}}</text>
				</view>
				<view class="wocomplete-listprocess__divider"></view>
				<view class="wocomplete-listprocess__item">
					<text class="wocomplete-listprocess__title">完工处理：{{orderDetailData.FinishedHandleStateName}}</text>
					<text class="wocomplete-listprocess__desc">{{orderDetailData.FinishHandleInfo}}</text>
				</view>
			</view>
		</view>
		<view class="wocomplete-footer">
			<button class="cu-btn lg primary block plain" @click="onCancel">取消</button>
			<button class="cu-btn lg primary block" @click="onSumbit">提交</button>
		</view>
	</view>
</template>

<script>
	import yuDatetimePicker from "@/components/yu-datetime-picker/yu-datetime-picker.vue"
	import waterQuality from "@/components/WaterQualityPopup"
	import uniCalendar from '@dcloudio/uni-ui/lib/uni-calendar/uni-calendar.vue'
	import AGInput from '@/components/AGInput';
	import repairbehavior from './repairbehavior';
	import ListImage from "../../../components/ListImage";
	import AutoMapper from "@/common/automapper";
	import Utils from '../../../common/utils';
	export default {
		mixins: [repairbehavior],
		components: {
			AGInput,
			ListImage,
			uniCalendar,
			yuDatetimePicker,
			waterQuality,
		},
		data() {
			return {
				orderDetailData: {},
				orderDataCache: {},
				orderDetailId: "",
				OrderRremark: "",
				CustomerRequiresMaintenanceDate: "",
				ActualReceiptAmount: "",
				startYear: new Date().getFullYear() - 1,
				addrepairData: [],
				//维修信息总数量
				addrepairDataTotal: 0,
				//维修信息总金额
				PriceTotal: 0,

				proItemIndex: 0,
				isShowActualReceiptAmountField: false,

			}
		},
		filters: {
			//保内保外显示值
			displayOrOffWarranty(value) {
				if (value) {
					switch (value) {
						case 1:
							return "保外";
						case 2:
							return "保内";
						case 3:
							return "保外转保内";
						default:
							return "";
					}
				}
				return "";
			},

			//获取日期
			GetDate(value) {
				if (value) {
					var date = value.replace(/-/g, '/')
					let result = Utils.formatDate(new Date(date), 'yyyy/MM/dd');
					return result;
				}
				return '';
			},
		},
		watch: {
			'orderDetailData': {
				handler(newval, oldval) {
					if (newval.hasOwnProperty("WoProuduct") &&
						newval.WoProuduct.length > 0) {
						this.initData(newval);
						console.log(newval);
					}
				}
			},
			'orderDetailData.WoProuduct': {
				handler(newval, oldval) {
					if (newval.length > 0) {
						for (let index in newval) {
							let Repairs = newval[index].Repairs;
							this.total(Repairs);
						}
					}
				}
			},
			'addrepairData': {
				handler(newval, oldval) {
					if (newval.length > 0) {
						this.total(newval);
						console.log(this.addrepairData);
					}
				}
			},
		},

		onLoad(Option) {

			uni.$on('reLoadInstall', () => {
				this.GetOrderDataImg().then((succ) => {
					this.orderDetailData.WoItemPicture = succ;
				}, (err) => {
					console.log(err);
				})
			});

			//选择产品后刷新
			uni.$on('selectProdItem', (e) => {
				let upProdItem = this.orderDetailData.WoProuduct[e.prodIndex];
				console.log(e.prodItem, upProdItem);
				let selectProdItem = e.prodItem;
				upProdItem.ProductNum = selectProdItem.Name;
				upProdItem.ProductName = selectProdItem.ProductNumber;
				upProdItem.ProductId = selectProdItem.ProductId;
				upProdItem.ProdTypeGroup = selectProdItem.ProductTypeName;
				upProdItem.WaterAnalysisFieldRequired = selectProdItem.WaterAnalysisFieldRequired;
				upProdItem.FaultyGroup = selectProdItem.proFaultyGroup;
				upProdItem.FaultyGroupName = selectProdItem.proFaultyGroupName;
				upProdItem.ProductImage = e.proImage;

			})

			//添加维修信息
			uni.$on('addrepair', (data) => {

				this.addrepairData =
					this.orderDetailData.WoProuduct[this.proItemIndex].Repairs || [];

				debugger
				if (data) {
					if (data.Type == 'Edit' && this.addrepairData.length > 0) {
						this.addrepairData.splice(parseInt(data.editRepairIndex), 1, data.repairData);
					} else if (data.Type == 'Add') {

						console.log('Add', this.addrepairData, data.repairData);
						console.log(data.repairData);
						this.addrepairData.push(data.repairData);
						console.log("addrepairData.length：" + this.addrepairData.length);
					}
					this.orderDetailData.WoProuduct[this.proItemIndex].Repairs = this.addrepairData;
					
					console.log("维修信息");
					console.log(this.addrepairData);
				}
			});

			this.orderDetailId = Option.orderDetailId;
			console.log(this.orderDetailId);
			this.onLoadData();
		},
		onUnload() {
			uni.$off("reLoadInstall");
			uni.$off("selectProdItem");
			uni.$off("addrepair");
		},
		methods: {
			onLoadData() {
				uni.showLoading({
					title: "加载中",
					mask: true,
				});
				this.GetOrderData();
			},

			//删除维修信息
			DelRepairData(index) {
				let me = this;
				me.addrepairData = me.orderDetailData.WoProuduct[me.proItemIndex].Repairs;
				uni.showModal({
					title: '提示',
					content: '确认删除该条维修信息？',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							me.addrepairData.splice(index, 1);
							me.orderDetailData.WoProuduct[me.proItemIndex].Repairs = me.addrepairData;
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			//显示故障信息
			selectFaultItemPath(faultItem) {
				if (!faultItem) return "";
				let faultNameArray = [];
				faultNameArray.push(faultItem.Name);
				while (faultItem.hasOwnProperty('parentFaultItem')) {
					faultItem = faultItem.parentFaultItem
					faultNameArray.push(faultItem.Name)
				}
				let str = faultNameArray.reverse().join("--");
				console.log(str);
				return str;
			},
			//计算维修信息总数量与金额
			total(addrepairData) {
				this.PriceTotal = 0;
				this.addrepairDataTotal = 0;
				if (addrepairData && addrepairData.length > 0) {
					for (let index in addrepairData) {
						if (addrepairData[index].switchReplacePart == true) {
							this.addrepairDataTotal++;
						}
						if (addrepairData[index].faultPartItem.InOrOffWarranty == 1) {
							this.PriceTotal += addrepairData[index].changeFaultPartItem.Price;
						}
					}
				}
				this.isShowActualReceiptAmountField = this.GetActualReceiptAmountShow(addrepairData);
				this.orderDetailData.WoProuduct[this.proItemIndex].addrepairDataTotal = this.addrepairDataTotal;
				this.orderDetailData.WoProuduct[this.proItemIndex].PriceTotal = this.PriceTotal;
				console.log(this.addrepairDataTotal);

				console.log(this.PriceTotal);

				console.log("监听维修信息");
				console.log(this.orderDetailData.WoProuduct[this.proItemIndex]);
			},


			//编辑当前维修信息
			EditCurrentRepairData(repairIndex, proIndex) {
				let productItem = this.orderDetailData.WoProuduct[proIndex];
				// let editRepairData = this.addrepairData[repairIndex];
				let editRepairData = productItem.Repairs[repairIndex];
				uni.navigateTo({
					url: `../../addrepair/index?orderDetailId=` +
						`${this.orderDetailId}&prodItem=${encodeURIComponent(JSON.stringify(productItem))} 
					 &editRepairData= ${encodeURIComponent(JSON.stringify(
						editRepairData))}&editRepairIndex=${repairIndex}&Type=Edit`
				})
			},

			//添加维修信息
			onClickToAddrepair(index, e) {
				let productItem = this.orderDetailData.WoProuduct[index];
				if ((productItem.Barcode && productItem.ProductNum && productItem.PurchaseDate) || productItem.IsProductConfirmed ==
					true) {
					console.log(e, productItem);
					let tourl = `../../addrepair/index?orderDetailId=` +
						`${this.orderDetailId}&prodItem=${encodeURIComponent(JSON.stringify(productItem))}`
					uni.navigateTo({
						url: tourl
					});
					this.proItemIndex = index;
				} else {
					uni.showToast({
						title: "请输入物流码与产品及保修时间",
						icon: "none"
					});
				}
			},
			changeOrderRremark(e) {
				this.OrderRremark = e.detail.value;
			},

			changeRrpairType(e) {
				//console.log(e)
				this.repairTypeIndex = e.detail.value;
			},
			navToUploadImg(e) {
				uni.navigateTo({
					url: "../../woupload/index"
				})
			},
			onOpenCalender(index, e) {
				//debugger;
				console.log(index, e);
				if (index >= 0) {
					this.$refs.purchaseDatePicker[index].open();
				} else {
					if (this.CustomerRequiresMaintenanceDate) {
						this.$refs.cusReqDatePicker.init(this.CustomerRequiresMaintenanceDate);
						//this.$refs.cusReqDatePicker.showSetDate(this.CustomerRequiresMaintenanceDate);
					}
					this.$refs.cusReqDatePicker.open();
				}
			},
			purchaseConfirm(index, e) {
				console.log(index, e);
				let productItem = this.orderDetailData.WoProuduct[index]
				productItem.PurchaseDate = e.fulldate;
			},
			cusReqDateConfirm(e) {
				let selectRes = e.fulldate
				console.log(selectRes);
				this.CustomerRequiresMaintenanceDate = selectRes;
			},
			//扫描物流码
			onOpenQrcode(index, e) {
				let prodItem = this.orderDetailData.WoProuduct[index];
				if (prodItem.IsProductConfirmed == true) {
					uni.showToast({
						title: "产品已确认,不能输入物流码",
						icon: "none"
					});
				} else {
					// 调起条码扫描
					uni.scanCode({
						scanType: 'barCode',
						success: (res) => {
							prodItem.Barcode = res.result;
							uni.showLoading({
								mask: true,
							})
							this.BarcodeValidCheckAsync(index, prodItem.Barcode)
								.then((succ) => {
									let data = succ;
									this.RefreshProduct(data, index, prodItem.Barcode);
								}, (err) => {
									uni.hideLoading();
									uni.showToast({
										title: "物流码验证失败",
										icon: "none",
										duration: 3000
									});
								});
						}
					});
				}
			},
			//失去焦点验证物流码
			onBlurLogisticsCode(index, e) {
				//console.log(e);
				if (e.detail.value) {
					let productItem = this.orderDetailData.WoProuduct[index];
					let strOriBarcode = e.detail.value;
					let strBarcode = productItem.Barcode;

					if (strOriBarcode != strBarcode) {
						uni.showLoading({
							mask: true,
						})
						this.BarcodeValidCheckAsync(index, strOriBarcode)
							.then((succ) => {
								let data = succ;
								this.RefreshProduct(data, index, strOriBarcode);
							}, (err) => {
								uni.hideLoading();
								uni.showToast({
									title: "物流码验证失败",
									icon: "none",
									duration: 2000
								});
							});
					}
				}
			},
			//选择产品
			onOpenProdSearch(index, e) {
				//console.log("选择产品");
				let prodItem = this.orderDetailData.WoProuduct[index];
				if (!prodItem.isDisplayProdInputField) {
					uni.navigateTo({
						url: `../../productlist/index?action=selectproduct&prodIndex=${index}`
					})
				} else {
					uni.showToast({
						title: "不能选择产品",
						icon: "none",
						mask: true,
						duration: 800
					})
				}
			},
			//打开水质检测
			onOpenWaterQualityPopup(index, e) {
				// let productItem = this.orderDetailData.WoProuduct[index]
				// this.$refs.proItem = productItem;
				// this.$refs.fieldReq = this.ParseWaterAnalysisFieldRequired(productItem.WaterAnalysisFieldRequired);
				this.$refs.waterQuality[index].openPoPup();
			},
			//保存水质检测
			saveWaterQuality(index, e) {
				//console.log(e);
				let proItem = this.orderDetailData.WoProuduct[index];
				let formData = e;
				proItem.NewChlorine = formData.NewChlorinetxt;
				proItem.NewHardness = formData.NewHardnesstxt
				proItem.NewTDS = formData.NewTDStxt
				proItem.OriChlorine = formData.OriChlorinetxt
				proItem.OriHardness = formData.OriHardnesstxt
				proItem.OriTDS = formData.OriTDStxt
				proItem.OriTemperature = formData.OriTemperaturetxt
				proItem.IsWaterAnalysis = true;
				proItem.isShowWaterAnalysisAddBtn = false;
				this.$refs.waterQuality[index].closePoPup();
				//console.log(this.orderDetailData.WoProuduct[index]);
			},
			//移除水质检测
			onCanleWaterQuality(e) {
				let productItem = this.orderDetailData.WoProuduct[e];
				uni.showModal({
					title: "操作确认",
					content: "确认删除水质检测信息？",
					success: function(res) {
						if (res.confirm) {
							productItem.OriTDS = "";
							productItem.OriTemperature = "";
							productItem.OriHardness = "";
							productItem.OriChlorine = "";
							productItem.NewTDS = "";
							productItem.NewHardness = "";
							productItem.NewChlorine = "";
							productItem.isShowWaterAnalysisAddBtn = true;
							productItem.isWaterAnalysis = false;
						}
					}
				});
			},
			//确认产品
			onAffirmProduct(index) {
				let prodItem = this.orderDetailData.WoProuduct[index];
				if (prodItem.IsProductConfirmed == true) {
					uni.showToast({
						title: "产品已确认,不能输入物流码",
						icon: "none"
					});
				} else {
					uni.showLoading({
						title: "确认产品中..",
						mask: true,
					})
					this.AffirmProduct(index);
					//console.log("确认产品");
				}
			},
			onCancel(e) {
				uni.navigateBack();
			},
			onSumbit(e) {
				this.SubmitOrder();
			},

			//实际收款总额
			ChangeActualReceiptAmount(e) {
				this.ActualReceiptAmount = e;
				console.log(this.ActualReceiptAmount);
			},

			//定义提交工单空对象
			SetSumbitOrderData() {
				let sumbitOrderData = {};
				sumbitOrderData.UserId = '';
				sumbitOrderData.WOTrans = {
					ServiceOrder: '',
					Operator: '',
					Type: '',
					FinishType: '',
					Description: '',
					RepairType: '',
					IsRepalced: '',
					ActualReceivedAmount: '',
					CustomerRequiresMaintenanceDate: '',
				};
				sumbitOrderData.WOProducts = [];


			}



		}
	}
</script>

<style lang="scss">
	@import '../index.scss';
</style>
